#region Namespaces

using System;
using System.Xml;

#endregion

namespace Vibstudio.X4NET.Xml.Linq
{
    public class XProcessingInstruction : XNode
    {
        private string _data;

        private string _name;

        public XProcessingInstruction(string target, string data)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            _name = target;
            _data = data;
        }

        public XProcessingInstruction(XProcessingInstruction other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            _name = other._name;
            _data = other._data;
        }

        public string Data
        {
            get { return _data; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }
                _data = value;
            }
        }

        public override XmlNodeType NodeType
        {
            get { return XmlNodeType.ProcessingInstruction; }
        }

        public string Target
        {
            get { return _name; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }
                _name = value;
            }
        }

        public override void WriteTo(XmlWriter writer)
        {
            writer.WriteProcessingInstruction(_name, _data);
        }
    }
}